/**
 * Created by python on 18-12-13.
 */
var app = new Vue({
    el:"#app",
    data:{
       // 页面中需要使用到的数据，键值对
        host:HOST,
        activity:null,
        now :0,
        deadline:0,
        last_ms:0,
    },
    computed:{
        // 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数
    },
    mounted:function () {
        // 一加载就需要做的，直接是代码
        let id =get_query_string('id')

        axios.get(this.host + 'activities/'+ id + '/')
            .then(response=>{
                this.activity = response.data
                this.now = new Date(response.headers.date).getTime();
                this.deadline = new Date(this.activity.dead_line).getTime();
                setInterval(
                    ()=>{
                        this.now += 1000;
                        this.last_ms = this.deadline - this.now
                    }
                    ,1000);

            })
            // .catch(error=>{
            //
            // })

    },
    methods:{
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数

    },
    filters:{
        countdown2dhms: function (value_ms) {
            let seconds = value_ms / 1000
            let day = Math.floor(seconds / (60*60*24))
            let hour = Math.floor (seconds / (60*60)) % 24
            let minute = Math.floor(seconds / 60) % 60
            let second = seconds % 60

            return day + '天' + hour + '时' + minute + '分' + second + '秒';
        }
    }

})
